import {getTopCategoryAPI} from "@/apis/category.js";
import {onMounted,ref} from 'vue'
import { useRoute,onBeforeRouteUpdate } from "vue-router";
export function useCategory(){
    const route = useRoute();
    const categoryData = ref({})
    const getTopCategory = async(id)=>{
        const res = await getTopCategoryAPI(id);
        categoryData.value=res.data.result  
    }
    onMounted(()=>{
        getTopCategory(route.params.id)
    })
    onBeforeRouteUpdate((to)=>{
    getTopCategory(to.params.id)
    })

    return {
        categoryData
    }
}